package k3;

public class Stack <A>{
	private StackNode<A> topStackNode=null;
	private int size=0;
	
	/**
	 * place new element as the last element in a stack
	 * @param element
	 */
	public void push(A element){
		StackNode<A> node= new StackNode<A>();
		node.element=element;
		size++;
		if(isEmpty()){
			topStackNode=node;
			return;
		}
		else{
			node.stackNode=topStackNode;
			topStackNode=node;
		}
	}
	
	/**
	 * delete last element in a stack and return it
	 * @return
	 */
	public A pop(){
		//if(isEmpty())return -1;
		StackNode<A> node=topStackNode;
		topStackNode=node.stackNode;
		size--;
		return (A) node.element;
	}
	
	/**
	 * is stack empty or not
	 * @return
	 */
	public boolean isEmpty(){
		if(topStackNode==null)return true;
		return false;
	}
	
	public int getSize(){
		return size;
	}
}
